package com.xzc.dao;

import com.xzc.domain.User;

/**
 * @author 徐州城
 * @version 1.0
 */
public class UserDAO extends BasicDAO<UserDAO>{

    /**
     *  注册用户
     * @param user 用户参数，经过service的判断层，就可以存放入数据库了
     * @return 返回-1说明执行语句失败了
     */
    public int keepUser(User user){
        String sql = "insert into user(username,password,email) values(?,?,?)";
        return super.update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }


    /**
     *  根据用户名和用户密码查询用户
     * @param username
     * @param password
     * @return 返回null，用户名或密码错误
     */
    public User queryUserToUsernameAndPassword(String username,String password){
        String sql = "select id,username,password,email from user where username=? and password=?";
        return (User) super.queryToOne(sql,User.class,username,password);
    }


    /**
     * 查询用户是否可用
     * @param username
     * @return 返回null，说明没有该用户
     */
    public User queryUsernameToExist(String username){
        String sql = "select id,username,password,email from user where username=?";
        return (User) super.queryToOne(sql,User.class,username);
    }
}
